// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2023, Phytium Technology Co., Ltd.
 * lixinde			<lixinde@phytium.com.cn>
 * weichangzheng	<weichangzheng@phytium.com.cn>
 * This file describes the initialization of PLL
 * of the Phytium pe2201 board.
 */

#include <common.h>
#include <vsprintf.h>
#include <stdio.h>
#include <string.h>
#include <asm/io.h>
#include <linux/arm-smccc.h>
#include <e_uart.h>
#include "board.h"
#include "../cpu.h"
#include "../parameter/parameter.h"
#include "../power_manage/power_manage.h"

DECLARE_GLOBAL_DATA_PTR;

struct pll_config const pll_base_info = {
	.magic = PARAMETER_PLL_MAGIC,
	.version = 0x2,
	.size = 0x100,
	.clust0_pll = 2000,
	.clust1_pll = 2000,
	.clust2_pll = 2000,
	.noc_pll = 1800,
	.dmu_pll = 600,
};

void pll_init(void)
{
	u8 buffer[0x100];
	struct arm_smccc_res res;

	//get parameter from parameter table
	if ((get_parameter_info(PM_PLL, buffer, sizeof(buffer)))) {
		p_printf("use default parameter\n");
		memcpy(buffer, &pll_base_info, sizeof(pll_base_info));
	}

	arm_smccc_smc(CPU_INIT_PLL, 0, (u64)buffer, 0, 0, 0, 0, 0, &res);
	if (res.a0 != 0) {
		p_printf("error ret  %lx\n", res.a0);
		while (1);
	}
}
